import com.baomidou.mybatisplus.core.metadata.IPage;
import com.honeycombis.honeycom.common.core.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import com.honeycombis.honeycom.common.log.annotation.SysLog;
import com.honeycombis.honeycom.common.security.annotation.Inner;


/**
* @author :${author}
* @description: ${desc} controller
* @create date: ${createDate}
*/


@RestController
@RequestMapping(value = "${entityNameLower}")
@Tag(description = "${entityNameLower}", name = "${desc}管理模块")
@RequiredArgsConstructor
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ${entityName}Controller {

    @Autowired
    ${entityName}Service ${entityNameLower}Service;

    @Inner(value = false)
    @SysLog("新增${desc}")
    @PostMapping("/create")
    @Operation(summary = "新增${desc}" , description = "新增${desc}信息" )
    public ${returnCls}<Boolean> create(@RequestBody @Validated(${entityName}DTO.Add.class) ${entityName}DTO requestDTO ){
        return ${entityNameLower}Service.add(requestDTO) > 0?
        ${returnSuccess}():${returnFail}();
    }

    @Inner(value = false)
    @SysLog("修改${desc}")
    @PostMapping("/update")
    @Operation(summary = "修改${desc}" , description = "修改${desc}信息" )
    public ${returnCls}<Integer> update(@RequestBody @Validated(${entityName}DTO.Update.class) ${entityName}DTO requestDTO ){
        return ${entityNameLower}Service.update(requestDTO) > 0?
                ${returnSuccess}():${returnFail}();
     }

    <#if primaryKey!='noPrimaryKey'>
    @SysLog("删除${desc}")
    @Operation(summary = "删除${desc}" , description = "删除${desc}信息" )
    @GetMapping("/remove/{id}")
    public ${returnCls} <Integer> remove(@PathVariable Long id ){
        return ${entityNameLower}Service.remove(id)> 0?
                        ${returnSuccess}():${returnFail}();
    }

    @Inner
    @Operation(summary = "查询${desc}详情" , description = "查询${desc}详情信息" )
    @GetMapping("/detail/{id}")
    public ${returnCls}<${entityName}VO> detail(@PathVariable Long id){
        return ${returnSuccess}(${entityNameLower}Service.detail(id));
    }
    </#if>

    @Inner(value = false)
    @Operation(summary = "查询${desc}列表" , description = "查询${desc}列表" )
    @PostMapping("/list")
    public ${returnCls} findList(@RequestBody ${entityName}DTO requestDTO ){
        return ${returnSuccess}(${entityNameLower}Service.findList(requestDTO));
    }

    @Inner(value = false)
    @Operation(summary = "查询${desc}分页列表" , description = "查询${desc}分页列表" )
    @PostMapping("/page")
    public ${returnCls}<IPage<${entityName}VO>> findPageList(@RequestBody ${entityName}PageDTO requestDTO ){
        /*${entityName}DTO ${entityNameLower}DTO = requestDTO;
        Integer pageNum = ${entityNameLower}DTO.getPageNum();
        Integer pageSize = ${entityNameLower}DTO.getPageSize();
        pageNum=pageNum==null?0:pageNum;
        pageSize=pageSize==null?10:pageSize;
        ${entityNameLower}DTO.setPageNum(pageNum);
        ${entityNameLower}DTO.setPageSize(pageSize);*/
        return ${returnSuccess}(${entityNameLower}Service.findPageList(requestDTO));
    }
}